package flca.voicenav.test;


public class GetNaturalDirection {

	private static String sDirections[] = new String[] {"left ", "right "};
	private static int LEFT = 0;
	private static int RIGHT = 1;
	
	public static String getAngleAsString(double angle)
	{
 		int dir = LEFT; //assume
 		
		if (angle < 0.0)  {
			if (angle > -180.0) {
				angle = -angle;
			} else  {
				angle = 360.0 + angle;
			}
		} else {
			if (angle > 180.0) {
				angle = 360.0 - angle;
			} else {
				angle = 180.0 - angle;
				dir = RIGHT;
			}
		}
		
		return postProcessString(angle, dir);
	}

	private static String postProcessString(double angle, int dir)
	{
		int a = rounded(angle);
		if (a > 40) {
			return sDirections[dir] + rounded(angle);
		} else if (a > 20) {
			return dir == LEFT ? "keep left" : "keep right";
		} else {
			return ""; //dont say anything 
		}
	}

	private static int rounded(double aValue) {
		return ((int) Math.round(aValue/10.0)) * 10;
	}
	
}
